from zipfile import ZipFile
from re import findall
from docx import Document
import sys

fn = r"测试/你好世界.docx"

doc = Document(fn)

defname = []
ps = []
notes = []
for p in doc.paragraphs:
	if p.style.name=="Heading 1":
		defname.append(p.text)
	else:
		ps.append(p.text)
	for i, r in enumerate(p.runs):
		if r.style.name == "endnote reference":
			notes.append(p.runs[i-1].text)

print("模块：", defname[0])
print(ps)

with ZipFile(fn) as fp:
	try:
		content = fp.read('word/endnotes.xml').decode('utf8')
	except:
		content = ''

endnotes_text = findall(r'<w:t>(.*?)</w:t>', content)
for ii, item in zip(notes, endnotes_text):
	print(f"{ii}:{item}")